VPATH=.:../lib
CC=gcc
CXX=g++
INCLUDES=-I../include/
CFLAGS=-Wall -g -o2 $(INCLUDES)
LDFLAGS=
DEPLIBS=-lrt

TARGET = prodcons1 
TARGET_g:=$(foreach t,$(TARGET),$(t)_g)

SOURCES=$(foreach t,$(TARGET),$(t).c) 

COMMON_OBJS=my_error.o mem_pool.o inet.o event.o  thread_pool.o block_queue.o
OBJS = $(foreach t,$(TARGET),$(t).o)  
OBJS +=$(COMMON_OBJS)




all:$(TARGET)

$(TARGET):$(OBJS)
	$(CC) -g -o $@_g  $(LDFAGS) $(DEPLIBS) $@.o $(COMMON_OBJS) 
	cp $@_g $@
	strip $@

%.o:%.c
	$(CC) -c $(CFLAGS)  $<  -o $@

%.d:%.c
	@set -e; rm -f $@;\
	$(CC) -MM $(INCLUDES) $< > $@.$$$$;\
	sed 's,\($*\).o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;\
	rm -f $@.$$$$


include $(SOURCES:.c=.d)

#dummy rule
%.h:
	@:

distclean:clean

clean:
	rm -rf  *.o $(TARGET) $(TARGET_g) $(SOURCES:.c=.d) 

.PHONY: all clean distclean
